// 获取今天
function getToday() {
	var list = [];
	var date1 = "", date2 = "";
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1;//得到月份
	var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	// var time = now.getTime();//获取当前时间戳
	
	if (month < 10) { month = "0" + month };
	if (date < 10) { date = "0" + date };

	date1 = year + "-" + month + "-" + date + " 00:00:00";
	date2 = year + "-" + month + "-" + date + " 23:59:59";
	
	list = [date1,date2];
	
	return list;
};

// 获取昨天
function getYesterday() {
	var list = [];
	var date1 = "", date2 = "";
	var now = new Date();
	var time = now.getTime()  ;//获取当前时间戳
	
	now.setTime(time - (24*60*60*1000));
	
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1;//得到月份
	var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	
	
	if (month < 10) { month = "0" + month };
	if (date < 10) { date = "0" + date };

	date1 = year + "-" + month + "-" + date + " 00:00:00";
	date2 = year + "-" + month + "-" + date + " 23:59:59";
	
	list = [date1,date2];
	
	return list;
};

// 获取本月
function getThisMonth() {
	var list = [];
	var date1 = "", date2 = "";
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1;//得到月份
	var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	// var time = now.getTime();//获取当前时间戳
	
	if (month < 10) { month = "0" + month };
	if (date < 10) { date = "0" + date };
	
	date1 = year + "-" + month + "-" + "01 00:00:00";
	date2 = year + "-" + month + "-" + date + " 23:59:59";
	
	list = [date1,date2];
	
	return list;
};

// 获取上月
function getLastMonth() {
	var list = [];
	var date1 = "", date2 = "";
	var now = new Date();
	
	var year = now.getFullYear(); 
	var month = now.getMonth();
	if(month == 0) {
		month = 12;
		year = year - 1;
	}
	
	now = new Date(year, month, 0); // 获取最后一天
	
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1;//得到月份
	var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	// var time = now.getTime();//获取当前时间戳
	
	if (month < 10) { month = "0" + month };
	if (date < 10) { date = "0" + date };

	date1 = year + "-" + month + "-" + "01 00:00:00";
	date2 = year + "-" + month + "-" + date + " 23:59:59";
	
	list = [date1,date2];
	
	return list;
};

// 获取一个时间段 days当前时间往前多少天
function getTimeQuantum(days) {
	var list = [];
	var date1 = "", date2 = "";
	days = Number(days);
	
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1;//得到月份
	var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	var time = now.getTime();//获取当前时间戳
	
	if (month < 10) { month = "0" + month };
	if (date < 10) { date = "0" + date };

	date2 = year + "-" + month + "-" + date + " 23:59:59";

	var now2 = new Date();
	now2.setTime(time - (days*24*60*60*1000));
	
	var year2 = now2.getFullYear(); //得到年份
	var month2 = now2.getMonth() + 1;//得到月份
	var thatDay = now2.getDate();//得到日期

	if (month2 < 10) { month2 = "0" + month2 };
	if (thatDay < 10) { thatDay = "0" + thatDay };
	
	date1 = year2 + "-" + month2 + "-" + thatDay + " 00:00:00";
	
	list = [date1,date2];
	
	return list;
};

// 获取本年
function getThisYear() {
	var list = [];
	var date1 = "", date2 = "";
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	// var month = now.getMonth() + 1;//得到月份
	// var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	// var time = now.getTime();//获取当前时间戳
	
	// if (month < 10) { month = "0" + month };
	// if (date < 10) { date = "0" + date };
	
	date1 = year + "-" + "01" + "-" + "01 00:00:00";
	date2 = year + "-" + "12" + "-" + "31" + " 23:59:59";
	
	list = [date1,date2];
	
	return list;
};

// 获取本季度,或某年某一季度(1,2,3,4)
function getThisQuarter(quarter, paramsYear) {
	var list = [];
	var date1 = "", date2 = "";
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	if(paramsYear) {
		year = paramsYear;
	}
	
	var month = now.getMonth() + 1;//得到月份
	// var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	// var hour = now.getHours();//得到小时
	// var minu = now.getMinutes();//得到分钟
	// var sec = now.getSeconds();//得到秒
	// var MS = now.getMilliseconds();//获取毫秒
	// var time = now.getTime();//获取当前时间戳
	
	var startMonth = 0, endMonth = 0, endDate = 1;

	//第一季度
	if(quarter == 1 || (!quarter && month >= 1 && month <= 3)) {
		startMonth = 1;
		endMonth = 3;
		
		endDate = new Date(year,endMonth,0).getDate();
	}
	//第二季度
	else if (quarter == 2 || (!quarter && month >= 4 && month <= 6)) {
		startMonth = 4;
		endMonth = 6;
		endDate = new Date(year,endMonth,0).getDate();
	}
	
	//第三季度
	else if (quarter == 3 || (!quarter && month >= 7 && month <= 9)) {
		startMonth = 7;
		endMonth = 9;
		endDate = new Date(year,endMonth,0).getDate();
	}

	//第四季度
	else if (quarter == 4 || (!quarter && month >= 10 && month <= 12)) {
		startMonth = 10;
		endMonth = 12;
		endDate = new Date(year,endMonth,0).getDate();
	}
	else {}
	
	if (startMonth < 10) { startMonth = "0" + startMonth };
	if (endMonth < 10) { endMonth = "0" + endMonth };
	if (endDate < 10) { endDate = "0" + endDate };
	
	
	date1 = year + "-" + startMonth + "-" + "01 00:00:00";
	date2 = year + "-" + endMonth + "-" + endDate + " 23:59:59";
	
	list = [date1,date2];
	
	return list;
};

let dateMeans = {
	getToday,
	getYesterday,
	getThisMonth,
	getLastMonth,
	getTimeQuantum,
	getThisYear,
	getThisQuarter
}

const install = Vue => {
	Vue.prototype.dateMeans = dateMeans
}

export default {
	install
}